package com.sy.wz.demo.controller;

import com.sy.wz.client.ucenter.User.UserDto;
import com.sy.wz.common.Result;
import com.sy.wz.demo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Create by wongloong on 17-8-18
 */
@Api(value = "用户前置api")
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;


    @ApiOperation(value = "新增用户", notes = "新增用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "UserPo")
    })
    @PostMapping("/testAdd")
    public String testAdd(@RequestBody UserDto user) {
        userService.saveOrUpdate(user);
        return "success";

    }


    @ApiOperation(value = "获取用户", notes = "获取用户信息")
    @GetMapping("/list")
    @ResponseBody
    public Result list() {
        Result r=new Result<List<UserDto>>();
        List<UserDto> ul= userService.list();
        r.setObject(ul);
        return r;
    }
}
